package cn.com.datu.candid.ws.service.impl;

import cn.com.datu.candid.ws.entity.User;
import cn.com.datu.candid.ws.service.UserService;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * 备注说明：接口实现类名称前的注解targetNamespace是当前类实现接口所在包名称的反序（PS：加上反斜线），
 * endpointInterface是当前需要实现接口的全称；
 *
 * @WebService(targetNamespace="http://service.webservicedemo.dbgo.com/", endpointInterface = "com.dbgo.webservicedemo.service.UserService")
 */

@Service
@WebService(serviceName = "userService", targetNamespace = "http://service.ws.candid.datu.com.cn/",
        endpointInterface = "cn.com.datu.candid.ws.service.UserService")
public class UserServiceImpl implements UserService {
    
    private Map<String, User> userMap = new HashMap<String, User>();

    public UserServiceImpl() {
        System.out.println("向实体类插入数据");
        User user = new User();
        user.setUserId("411001");
        user.setUsername("zhansan");
        user.setAge("20");
        user.setUpdateTime(new Date());
        userMap.put(user.getUserId(), user);

        user = new User();
        user.setUserId("411002");
        user.setUsername("lisi");
        user.setAge("30");
        user.setUpdateTime(new Date());
        userMap.put(user.getUserId(), user);

        user = new User();
        user.setUserId("411003");
        user.setUsername("wangwu");
        user.setAge("40");
        user.setUpdateTime(new Date());
        userMap.put(user.getUserId(), user);
    }

    @Override
    public String getName(String userId) {
        return "liyd-" + userId;
    }

    @Override
    public User getUser(String userId) {
        User user = userMap.get(userId);
        return user;
    }

    @Override
    public ArrayList<User> getAlLUser() {
        ArrayList<User> users = new ArrayList<>();
        userMap.forEach((key, value) -> {
            users.add(value);
        });
        return users;
    }
}